from django.contrib.auth.hashers import make_password,check_password
from django.db import models
import time

from area.models import City


# 获取随机id
def rand_id():
    t = str(time.time()).split(".")[0] # 获取时间戳
    return t

class UserModel(models.Model):
    uid = models.CharField(max_length=15,primary_key=True,default=rand_id) # 用户id
    img = models.ImageField(upload_to="user/",default="user/default.png")   # 头像
    username = models.CharField(max_length=20,unique=True) # 账号
    password = models.CharField(max_length=256) # 密码
    email = models.CharField(max_length=32) # 邮箱
    nickname = models.CharField(max_length=20) # 昵称
    introduction = models.TextField(null=True) # 简介
    place = models.ForeignKey(City,on_delete=models.CASCADE,to_field="code") # 地址
    isAdmin = models.IntegerField(default=0)    # 是否为管理员

    class Meta:
        db_table = "user" # 指明表名
        verbose_name = "用户表" # 在admin站点显示名称

    def __str__(self):
        return f"{self.username} -- {self.nickname}"



